package com.compunit.composite;

public class Vector3f {

	float x;
	float y;
	float z;
	
	public Vector3f() {}
	
	public Vector3f(Vector3f vec) {
		this.set(vec.x, vec.y, vec.z);
	}
	
	public Vector3f(float x, float y, float z) {
		this.set(x, y, z);
	}
	
	public Vector3f add(Vector3f vec) {
		this.x += vec.x;
		this.y += vec.y;
		this.z += vec.z;
		return this;
	}
	
	public Vector3f subtract(Vector3f vec) {
		this.x -= vec.x;
		this.y -= vec.y;
		this.z -= vec.z;
		return this;
	}
	
	public Vector3f normalize() {
		float length = (float)Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z);
		if (Math.abs(length) > 0) {
			this.x /= length;
			this.y /= length;
			this.z /= length;
        }
		return this;
	}
	
	public Vector3f set(float x, float y, float z) {
		this.x = x;
		this.y = y;
		this.z = z;
		return this;
	}
}
